//
//  ShuaWordRequest.m
//  Learn
//
//  Created by apple on 2024/4/18.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "ShuaWordRequest.h"

@implementation ShuaWordRequest
+(void)request_getWordListWithPage:(NSInteger)page  reslut:(void(^)(NSMutableArray *array,BOOL isMore,BOOL isRequest))resultBlock {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:@(page) forKey:@"page"];
    [param setValue:@(10) forKey:@"limit"];

    NSString *url = [NSString stringWithFormat:@"%@%@",BaseUrl,KM_API_brushWordList];
    [BaseRequest baseGET:url cache:NO autoHideLoading:YES parms:param request:^(id resultObject, NSError *error) {
        if (resultObject != nil && [resultObject[@"code"] integerValue] == 1) {
            NSMutableArray *array = [ShuaWordModel mj_objectArrayWithKeyValuesArray:resultObject[@"data"]];
        

            BOOL ismore = !(array.count <= 10);
            resultBlock(array,ismore,YES);
        } else {
            resultBlock(@[].mutableCopy,NO,NO);
        }
    }];
}

+(void)request_getWordInfoWithId:(NSString*)wordId reslut:(void(^)(ShuaWordModel *model,BOOL isRequest))resultBlock {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:wordId forKey:@"words_id"];

    NSString *url = [NSString stringWithFormat:@"%@%@",BaseUrl,KM_API_getShuaWordInfo];
    [BaseRequest baseGET:url cache:NO autoHideLoading:YES parms:param request:^(id resultObject, NSError *error) {
        if (resultObject != nil && [resultObject[@"code"] integerValue] == 1) {
            NSDictionary *dic = (NSDictionary *)resultObject[@"data"];
            ShuaWordModel *model = [ShuaWordModel mj_objectWithKeyValues:dic];
            resultBlock(model,YES);
        } else {
            resultBlock([ShuaWordModel new],NO);
        }
    }];
}



+(void)request_postAddWord:(NSString *)wordId score:(NSString *)score reslut:(void(^)(BOOL isRequest))resultBlock {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:wordId forKey:@"words_id"];
    [param setValue:score forKey:@"score"];

    NSString *url = [NSString stringWithFormat:@"%@%@",BaseUrl,KM_API_addWords];
    [BaseRequest basePOST:url cache:NO autoHideLoading:NO parms:param result:^(id resultObject, NSError *error) {
        if (resultObject != nil && [resultObject[@"code"] integerValue] == 1) {
            resultBlock(YES);
        } else {
            resultBlock(NO);
        }
    }];
}
@end
